package a10_动态规划;

/**
 * <p>
 * a17_一和零复习4
 * </p>
 *
 * @author flyduck
 * @since 2025/4/14
 */
public class a17_一和零复习4 {

    //dp[i][j]：包含i个0和j个1的最大个数
    public int findMaxForm(String[] strs, int m, int n) {
        int[][] dp = new int[m+1][n+1];
        for (String str : strs) {
            int x = 0;
            int y = 0;
            for (char c : str.toCharArray()) {
                if(c == '0'){
                    x++;
                }else {
                    y++;
                }
            }

            for (int i = m; i >= x; i--) {
                for (int j = n; j >=y; j--) {
                    dp[i][j] = Math.max(dp[i][j], dp[i-x][j-y] + 1);
                }
            }
        }
        return dp[m][n];
    }
}
